package com.ie.mapper.before;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ie.entity.admin.CartEntity;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CartMapper extends BaseMapper<CartEntity> {
    List<CartEntity> selectByUserId(@Param("userId") Integer userId);

    // 根据用户ID和商品ID查询购物车项
    CartEntity selectByUserIdAndGoodsId(
            @Param("userId") Integer userId,
            @Param("goodsId") Integer goodsId
    );

    // 根据用户ID删除购物车
    int deleteByUserId(@Param("userId") Integer userId);

    // 获取用户购物车商品数量
    int selectCountByUserId(@Param("userId") Integer userId);
    List<CartEntity> selectByBusertableId(@Param("busertableId") Integer busertableId);
}


//// 修正参数类型为 Integer，并添加 @Select 注解
//@Select("SELECT * FROM carttable WHERE busertable_id = #{userId}")
//List<CartEntity> selectByUserId(@Param("userId") Integer userId);
//
//// 根据用户ID和商品ID查询购物车项
//@Select("SELECT * FROM carttable WHERE busertable_id = #{userId} AND goodstable_id = #{goodsId}")
//CartEntity selectByUserIdAndGoodsId(
//        @Param("userId") Integer userId,
//        @Param("goodsId") Integer goodsId
//);
//
//// 根据用户ID删除购物车
//@Delete("DELETE FROM carttable WHERE busertable_id = #{userId}")
//int deleteByUserId(@Param("userId") Integer userId);
//
//// 获取用户购物车商品数量
//@Select("SELECT COUNT(*) FROM carttable WHERE busertable_id = #{userId}")
//int selectCountByUserId(@Param("userId") Integer userId);
//
//// 修正参数类型为 Integer，并添加 @Select 注解
//@Select("SELECT * FROM carttable WHERE busertable_id = #{busertableId}")
//List<CartEntity> selectByBusertableId(@Param("busertableId") Integer busertableId);
//}